<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>

                            <li>
                                名称：<input type="text" name="title"/>
                            </li>
                            <li>
                                审核状态：<select name="state" >
                                <option value="">所有</option>
                                <option value="0">未审核</option>
                                <option value="1">已审核</option>
                            </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:doc:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:doc:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>


            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:doc:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:doc:remove')}]];
        var prefix = ctx + "system/doc";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "文档管理",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'docid',
                        title: '文档ID',
                        hidden:true
                    },
                {
                    field: 'path',
                    title: '封面',
                    formatter: function(value, row, index) {
                        // 图片预览（注意：如存储在本地直接获取数据库路径，如有配置context-path需要使用ctx+路径）
                        // 如：/profile/upload/2019/08/08/3b7a839aced67397bac694d77611ce72.png
                        if(/https?:\/\//i.test(value))
                            return $.table.imageView(value);
                        else
                            return $.table.imageView(ctx+value);



                    }
                },

                {
                    field: 'nickname',
                    title: '上传者'
                },
                {
                    field: 'title',
                    title: ' 标题'
                },
                {
                    field: 'typename',
                    title: '分类'
                },
                {
                    field: 'preview',
                    title: '免费'
                },
                {
                    field: 'readpay',
                    title: '阅读币'
                },
                {
                    field: 'downpay',
                    title: '下载币'
                },
                {
                    field: 'readcount',
                    title: '阅读量'
                },
                {
                    field: 'downcount',
                    title: '下载量'
                },
                {
                    field: 'pcount',
                    title: '页数'
                },
                {
                    field: 'docsize',
                    title: '大小'
                },
                {
                    field: 'insertdate',
                    title: '添加时间'
                },
                {
                        title: '转换情况',
                        formatter: function(value, row, index) {
                            var actions = [];
                            if(row.pcount>0)
                                actions.push('<span class="badge badge-primary">转换成功</span>');
                            else
                                actions.push('<span class="badge badge-info">转换失败</span>');
                            return actions.join('');
                        }
                },
                {
                    title: '标识',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.isvip==1)
                            actions.push('<span class="badge badge-primary">vip</span>');
                        if(row.isimp==1)
                            actions.push('<span class="badge badge-info">推荐</span>');
                        if(row.downpay==0)
                            actions.push('<span class="badge badge-success">免费</span>');
                        if(row.state==0)
                            actions.push('<span class="badge badge-warning">未审核</span>');
                        else
                            actions.push('<span class="badge badge-success">已审核</span>');
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.docid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.docid + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="download1(\'' + row.docid + '\')"><i class="fa fa-edit"></i>下载</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="change(\'' + row.docid + '\')"><i class="fa fa-edit"></i>重新转换</a> ');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function resetPre() {
            resetDate();
            $("#formId")[0].reset();
            $.table.search();
        }
        /* 用户管理-停用 */
        function change(docid) {
            $.modal.confirm("确认要转换吗？", function() {
                $.operate.post(prefix + "/change", { "ids": docid});
            })
        }
        function download1(docid) {
            //$.operate.post(prefix + "/download", { "docid": docid});
            window.location.href = prefix + "/download?docid="+docid;
        }
    </script>
</body>
</html>